package com.bird.generate.ddd.remote

import cn.dev33.satoken.annotation.SaIgnore
import com.bird.component.lang.common.response.JSONResponse
import com.bird.component.lang.common.response.success
import com.bird.generate.ddd.application.GenerateApplication
import com.bird.generate.ddd.application.pl.AddAggregateRootRequest
import jakarta.servlet.http.HttpServletResponse
import org.springframework.web.bind.annotation.PostMapping
import org.springframework.web.bind.annotation.RequestBody
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RestController


/**
 * 用户控制器
 */
@RestController
@RequestMapping("/generate")
class GenerateController(private val generateApplication: GenerateApplication) {

    /**
     * 添加聚合根
     */
    @SaIgnore
    @PostMapping("/addAggregateRoot")
    fun addAggregateRoot(@RequestBody addAggregateRootRequest: AddAggregateRootRequest):JSONResponse<Long> {
        return success {
            generateApplication.addAggregateRoot(addAggregateRootRequest)
        }
    }
    /**
     * 生成聚合根
     */
    @SaIgnore
    @PostMapping("/generateAggregateRoot")
    fun generateAggregateRoot(aggregateRootId: Long):JSONResponse<Unit> {
        return success {
            generateApplication.generateAggregateRoot(aggregateRootId)
        }
    }

    /**
     * 生成聚合根
     */
    @SaIgnore
    @PostMapping("/download")
    fun download(@RequestBody addAggregateRootRequest: AddAggregateRootRequest,httpServletResponse: HttpServletResponse) {
        var addAggregateRoot = generateApplication.addAggregateRoot(addAggregateRootRequest)
        generateApplication.generateAggregateRoot(addAggregateRoot!!)
        generateApplication.download(addAggregateRootRequest.name ,httpServletResponse)

    }


}